package cate.game.role.res.call;

import cate.common.table.call.row.CallWeightRow;
import cate.game.role.Role;
import cate.game.role.RoleDependent;
import cate.game.role.res.call.base.CallBaseData;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteField;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.Map;
import java.util.Set;


public abstract class CallBasePO extends RoleDependent {
  @NoteField(value = "召唤基础数据")
  public CallBaseData baseData;

  @JsonIgnore
  @NoteField(value = "公用")
  public CallTool tool;

  public void initialize(Role role, CallTool tool) {
    super.initialize(role);
    this.tool = tool;
    if (baseData == null) {
      baseData = new CallBaseData();
    }
    handlerRegister();
  }

  protected void handlerRegister() {
    Set<Integer> typeSet = role.getGame().table.call.base.getModeAllType(getMode());
    typeSet.forEach(CallManager::register);
  }

  protected abstract byte getMode();

  protected abstract void noticeUpdate(Role role);

  public Collection<CallWeightRow> onGetPool(int groupId) {
    Map<Integer, CallWeightRow> list = role.getGame().table.call.weight.groupMap.get(groupId);
    if (list.isEmpty()) {
      role.getGame().notice.message(role, "配置错误");
      return null;
    }
    return list.values();
  }

}
